<template>
	<view>
		<view class="text-primary padding-top-xl margin-lr">Click to query the data package after input the ICCID</view>
		<view class="cu-card margin-top">
			<view class="cu-item" style="border: 2upx solid #efeded">
				<view class="cu-form-group uni-relative" style="min-height: 84upx;">
					<input class="text-align:left" placeholder-class="text-df text-gray" placeholder="Please enter you ICCID" name="iccid"
						v-model.trim="iccid" @input="iccidInput" @blur="pageScrollTo" />
					<view class="uni-input-group-append" @tap="handleGoBuy">Query</view>	
				</view>
			</view>
		</view>
		<view>
			<!-- <uni-list-item v-if="searchList.length && listShow" subTextClass="text-lg" :list="searchList" @click="(item)=>{iccid=handleReplace(item.iccid);listShow=false}" ></uni-list-item> -->
			<!-- <view v-else class="text-center" @tap="handleRecord">Recharge Record<text class="lg text-gray cuIcon-right"></text></view> -->
		</view>
		
		<view v-if="searchList.length" class="padding"></view>
		<search-prompt-modal v-model:modalName="modalName"></search-prompt-modal>
	</view>
</template>

<script>
import searchPromptModal from './searchPrompt/searchPrompt'
export default {
	components: {
	   searchPromptModal
	},
  data() {
    return {
     	iccid:'',//输入的卡号
		searchList:[],//搜索卡号结果
		modalName:'',//模态框弹出字段
		errCode:'',//失败code值
		errMessage:{},//失败接口返回的data信息
		listShow:false
    }
  },
    onLoad(opt) {
    
    },
    onShow() {
	},
    methods: {
		// input 事件
		iccidInput(e){
			this.iccid = handleReplace(e.detail.value);
			let iccidVal = this.iccid.replace(/\s+/g,"")
			if(iccidVal){
				handleSearch(iccidVal)
			}
		},
		handleReplace (val){
			return val.replace(/\s/g, '').replace(/(.{4})/g, "$1 ")
		},
		pageScrollTo () {
			uni.pageScrollTo({
				scrollTop: 0,
				duration: 0
			});
		},
		// iccid搜索
		handleSearch(iccidVal){
			iccidSearch({iccid:iccidVal,page:1,limit:300}).then(res=>{
				httpReturn(res, (data) => {
					let datas = data || [];
					this.listShow = true;
					if(datas.length){
						data.forEach((z,i)=>{
							let Num = Number(i)+1;
							z.title = `robote${Num}`;
							z.subText = z.iccid ? handleReplace(z.iccid) :'';
						})
						this.searchList = datas;
					}
				}, (code,data) => {
					this.modalName = 'errorMessage';//接口返回错误弹框
					this.errCode = code;
					this.errMessage = data;//接口返回的错误data
				})
			})
		},
		// 去购买
		handleGoBuy(){
			let iccidVal = this.iccid.replace(/\s+/g,"")
			if(iccidVal){
				// iccidSearch({iccid:iccidVal,page:1,limit:300}).then(res=>{
				// 	httpReturn(res, (data) => {
				// 		if(data&&data.length===1){
				// 			if(data[0].iccid===iccidVal){
				// 				// proxy.$routing(`${proxy.$pages.iccid.goods}?deviceId=${iccidVal}`)
				// 			}
				// 		}else{
				// 			this.modalName = 'iccidErrorModal'
				// 		}
				// 	})
				// })
			}
		},
		// 跳转历史记录
		handleRecord(){
			// proxy.$routing(`${proxy.$pages.iccid.record}?deviceId=${state.iccid}`)
		}
    }
}
</script>

<style>
</style>